package com.inspur.gs.sbssdl.sbyxgl.djjh.djjh.front.sbdjpzmx_frm.voactions;
import com.inspur.edp.bef.api.lcp.ILcpFactory;
import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.api.services.IBefSessionManager;
import com.inspur.edp.bff.spi.*;
import com.inspur.edp.bef.api.action.*;
import com.inspur.edp.cef.entity.changeset.ModifyChangeDetail;
import com.inspur.edp.cef.entity.entity.IEntityDataCollection;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

import java.util.ArrayList;
import java.util.List;

public class unlinkDataVOAction extends AbstractFSAction<VoidActionResult> {

	private String mainid;
	private String[] childids;
	public unlinkDataVOAction(String mainid,String[] childids) {

		this.mainid = mainid;
		this.childids = childids;
	}
	@Override
	public void execute() {
		ArrayList<String> ids = new ArrayList<>();
 		for (String childid : childids) {
			ids.add(childid);
		}
		SpringBeanUtils.getBean(IBefSessionManager.class).createSession();
		try {
//			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
//			String djxzid = "ff554cce-1197-469a-88f1-814f2ed0781d";// 设备点检配置明细id
//			IStandardLcp djxzlcp = iLcpFactory.createLcpByBEId(djxzid);
//
//			// 主表变更
//			ModifyChangeDetail curChange = new ModifyChangeDetail(mainid);
//			ArrayList<String> nodeCodes = new ArrayList<>();
//			nodeCodes.add("sbdjpzmx");//真实子表编号
//
//			//hierachyIdList包含主表数据的唯一标识
//			ArrayList<String> hierachyIdList = new ArrayList<>();
//			hierachyIdList.add(mainid);
//
//			djxzlcp.deleteChild(nodeCodes,hierachyIdList,ids);
//			djxzlcp.save();

			ILcpFactory iLcpFactory = SpringBeanUtils.getBean(ILcpFactory.class);
			String djid = "ff554cce-1197-469a-88f1-814f2ed0781d";// 设备点检配置明细id
			IStandardLcp djlcp = iLcpFactory.createLcpByBEId(djid);
			IEntityDataCollection sbdjpzmx = djlcp.retrieve(mainid).getData().getChilds().get("sbdjpzmx");
			if (sbdjpzmx.size()==ids.size()){
				ModifyChangeDetail curChange = new ModifyChangeDetail(mainid);
				curChange.getPropertyChanges().put("djpz",false);
				djlcp.modify(curChange);
				djlcp.save();
			}

			String djxzid = "d63f2f8e-2c5d-441d-9ba7-1edc3712159c";// 设备点检配置明细id
			IStandardLcp djxzlcp = iLcpFactory.createLcpByBEId(djxzid);
			djxzlcp.delete(ids);
			djxzlcp.save();




	} finally {
		SpringBeanUtils.getBean(IBefSessionManager.class).closeCurrentSession();
	}
	}
}
